//
// CVPInstruction.java
// Copyright (C) 2010  "Naush" <naush _ hotmail _ fr>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>./* ----------------------------------------------------------------------------







package org.ryzom.nel.threed;

public class CVPInstruction {
  private long swigCPtr;
  protected boolean swigCMemOwn;

  public CVPInstruction(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  public static long getCPtr(CVPInstruction obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        nel3dJNI.delete_CVPInstruction(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public void setOpcode(CVPInstruction.EOpcode value) {
    nel3dJNI.CVPInstruction_Opcode_set(swigCPtr, this, value.swigValue());
  }

  public CVPInstruction.EOpcode getOpcode() {
    return CVPInstruction.EOpcode.swigToEnum(nel3dJNI.CVPInstruction_Opcode_get(swigCPtr, this));
  }

  public void setDest(CVPOperand value) {
    nel3dJNI.CVPInstruction_Dest_set(swigCPtr, this, CVPOperand.getCPtr(value), value);
  }

  public CVPOperand getDest() {
    long cPtr = nel3dJNI.CVPInstruction_Dest_get(swigCPtr, this);
    return (cPtr == 0) ? null : new CVPOperand(cPtr, false);
  }

  public void setSrc1(CVPOperand value) {
    nel3dJNI.CVPInstruction_Src1_set(swigCPtr, this, CVPOperand.getCPtr(value), value);
  }

  public CVPOperand getSrc1() {
    long cPtr = nel3dJNI.CVPInstruction_Src1_get(swigCPtr, this);
    return (cPtr == 0) ? null : new CVPOperand(cPtr, false);
  }

  public void setSrc2(CVPOperand value) {
    nel3dJNI.CVPInstruction_Src2_set(swigCPtr, this, CVPOperand.getCPtr(value), value);
  }

  public CVPOperand getSrc2() {
    long cPtr = nel3dJNI.CVPInstruction_Src2_get(swigCPtr, this);
    return (cPtr == 0) ? null : new CVPOperand(cPtr, false);
  }

  public void setSrc3(CVPOperand value) {
    nel3dJNI.CVPInstruction_Src3_set(swigCPtr, this, CVPOperand.getCPtr(value), value);
  }

  public CVPOperand getSrc3() {
    long cPtr = nel3dJNI.CVPInstruction_Src3_get(swigCPtr, this);
    return (cPtr == 0) ? null : new CVPOperand(cPtr, false);
  }

  public CVPOperand getSrc(long index) {
    return new CVPOperand(nel3dJNI.CVPInstruction_getSrc(swigCPtr, this, index), false);
  }

  public long getNumUsedSrc() {
    return nel3dJNI.CVPInstruction_getNumUsedSrc(swigCPtr, this);
  }

  public CVPInstruction() {
    this(nel3dJNI.new_CVPInstruction(), true);
  }

  public final static class EOpcode {
    public final static EOpcode MOV = new EOpcode("MOV", nel3dJNI.CVPInstruction_MOV_get());
    public final static EOpcode ARL = new EOpcode("ARL");
    public final static EOpcode MUL = new EOpcode("MUL");
    public final static EOpcode ADD = new EOpcode("ADD");
    public final static EOpcode MAD = new EOpcode("MAD");
    public final static EOpcode RSQ = new EOpcode("RSQ");
    public final static EOpcode DP3 = new EOpcode("DP3");
    public final static EOpcode DP4 = new EOpcode("DP4");
    public final static EOpcode DST = new EOpcode("DST");
    public final static EOpcode LIT = new EOpcode("LIT");
    public final static EOpcode MIN = new EOpcode("MIN");
    public final static EOpcode MAX = new EOpcode("MAX");
    public final static EOpcode SLT = new EOpcode("SLT");
    public final static EOpcode SGE = new EOpcode("SGE");
    public final static EOpcode EXPP = new EOpcode("EXPP");
    public final static EOpcode LOG = new EOpcode("LOG");
    public final static EOpcode RCP = new EOpcode("RCP");
    public final static EOpcode OpcodeCount = new EOpcode("OpcodeCount");

    public final int swigValue() {
      return swigValue;
    }

    public String toString() {
      return swigName;
    }

    public static EOpcode swigToEnum(int swigValue) {
      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
        return swigValues[swigValue];
      for (int i = 0; i < swigValues.length; i++)
        if (swigValues[i].swigValue == swigValue)
          return swigValues[i];
      throw new IllegalArgumentException("No enum " + EOpcode.class + " with value " + swigValue);
    }

    private EOpcode(String swigName) {
      this.swigName = swigName;
      this.swigValue = swigNext++;
    }

    private EOpcode(String swigName, int swigValue) {
      this.swigName = swigName;
      this.swigValue = swigValue;
      swigNext = swigValue+1;
    }

    private EOpcode(String swigName, EOpcode swigEnum) {
      this.swigName = swigName;
      this.swigValue = swigEnum.swigValue;
      swigNext = this.swigValue+1;
    }

    private static EOpcode[] swigValues = { MOV, ARL, MUL, ADD, MAD, RSQ, DP3, DP4, DST, LIT, MIN, MAX, SLT, SGE, EXPP, LOG, RCP, OpcodeCount };
    private static int swigNext = 0;
    private final int swigValue;
    private final String swigName;
  }

}
